<?php
define('MINI_RUN', true);
require 'mini.php';
Mini::checkLogin();
?>
<!DOCTYPE html>
<html>
<head>
<title>查看栏目列表--<?=Mini::NAME?>后台管理系统</title>
<?=Mini::ADMIN_CSS?>
</head>
<body>
<table border="1" bordercolor="#09C" width="100%" cellpadding="3" cellspacing="0">
<tr>
	<td width="10%" align="center">栏目ID</td>
	<td width="35%" align="center">栏目标题</td>
	<td width="15%" align="center">栏目所在文件夹</td>
	<td width="20%" align="center">栏目首页模板</td>
	<td width="20%" align="center">栏目内容模板</td>
</tr>
<?php 
	//判断$_GET['page']变量是否设置，获取当前页数
	if (isset($_GET['page'])){
		$page = intval($_GET['page']);
	}else 
		$page = 1;
	//设置每页的记录数量为10
	$pageNums = 4;
	//获取总的页面数=记录数/10
	$arr = Mini::getClassList(($page-1)*$pageNums,$pageNums);
	$pdo = new MysqlPDO();
	$array = $pdo->selectSQL('select count(*) nums from mini_class');
	//数据库记录的条数
	$len = $array[0]['nums'];
	$amount = count($arr);
	$pageTotal = $len/$pageNums;
	if (!is_int($pageTotal)) {
		$pageTotal = intval(++$pageTotal);
	}
	$pageOut = '';
	if ($page==1) {
		$pageOut .='&nbsp;&nbsp;&nbsp;<a href="classList.php?page='.($page+1).'">下一页</a>|&nbsp;&nbsp;&nbsp;<a href="classList.php?page='.$pageTotal.'">尾页&nbsp;&nbsp;</a>';
	}
	else{
		$pageOut .='<a href="classList.php?page=1">&nbsp;&nbsp;&nbsp;第一页</a>|<a href="classList.php?page='.($page-1).'">&nbsp;&nbsp;&nbsp;上一页&nbsp;&nbsp;</a>|';
	}
	if ($page == $pageTotal || $pageTotal == 0) {
		$PageOut .= '<a href="classList.php?page=1">&nbsp;&nbsp;&nbsp;第一页</a>|<a href="classList.php?page='.($page-1).'">&nbsp;&nbsp;&nbsp;上一页&nbsp;&nbsp;</a>|';
	}
	else {
		 $PageOut .=  '<a href="classList.php?page='.($page+1).'">&nbsp;&nbsp;&nbsp;下一页</a>|<a href="classList.php?page='.$pageTotal.'">&nbsp;&nbsp;&nbsp;尾页&nbsp;&nbsp;</a>';
	}
	
	if ($arr) {
		for ($i = 0; $i < $amount; $i++) {
?>
<tr>
	<td width="10%" align="center"><?php echo $arr[$i]['classid'];?></td>
	<td width="35%" align="center"><?php echo $arr[$i]['classname'];?></td>
	<td width="15%" align="center"><?php echo $arr[$i]['classdir'];?></td>
	<td width="20%" align="center"><?php echo $arr[$i]['classtempname'];?></td>
	<td width="20%" align="center"><?php echo $arr[$i]['pagetempname'];?></td>
</tr>
<?php 
		}

?>

</table>
<?php 
	echo $PageOut;
	for($i=1;$i<=$pageTotal;$i++){//数字分页
            echo ($i!=$page)?"<a href='classList.php?page=".$i."'>&nbsp;&nbsp;$i&nbsp;&nbsp;</a>":"<b>$i</b>";
    }
          echo '&nbsp;&nbsp;&nbsp;&nbsp;共'.$len.'条记录,每页'.$pageNums.'条，共'.$pageTotal.'页';
	}
?>
</body>
</html>